/*
* @File Name: collideDataMover.c
* @File Path: K:\work\MAS2\PRM_robotic_arm\PRMCcode\coding\acc\collideDataMover.c
* @Author: 29505
* @Date:   2019-07-21 22:35:05
* @Last Modified by:   29505
* @Last Modified time: 2019-07-23 21:39:17
* @Email: 295054118@whut.edu.cn
*/

/*
* @File Name collideDataMover.c
* @File Path M:\MAS2\PRM_Robotic_Arm\PRMCcode\coding\acc\collideDataMover.c
* @Author: Ruige_Lee
* @Date:   2019-07-21 14:02:18
* @Last Modified by:   Ruige_Lee
* @Last Modified time: 2019-07-21 20:16:58
* @Email: 295054118@whut.edu.cn
* @page: https://whutddk.github.io/
*/


#include <stdint.h>
#include <stdio.h>

#include "xil_printf.h"



#include "xaxicdma.h"
#include "xdebug.h"
#include "xil_exception.h"
#include "xil_cache.h"
#include "xparameters.h"


#include "xscugic.h"


/******************** Constant Definitions **********************************/


#define DMA_CTRL_DEVICE_ID	XPAR_AXICDMA_0_DEVICE_ID

#define BUFFER_BYTESIZE		8192	/* Length of the buffers for DMA transfer */
#define RESET_LOOP_COUNT	10	/* Number of times to check reset is done */




/************************** Variable Definitions *****************************/

static XAxiCdma AxiCdmaInstance;	/* Instance of the XAxiCdma */

/* Shared variables used to test the callbacks.*/
volatile static int Error = 0;	/* Dma Bus Error occurs */


static int32_t dataCheck()
{
	return 0;
}



int main()
{
	Xil_DCacheDisable();
	Xil_ICacheDisable();

	XAxiCdma_Config *CfgPtr;

	CfgPtr = XAxiCdma_LookupConfig(DMA_CTRL_DEVICE_ID);
	if ( NULL == CfgPtr )
	{
		return XST_FAILURE;
	}

	if (XST_SUCCESS != XAxiCdma_CfgInitialize(&AxiCdmaInstance, CfgPtr, CfgPtr->BaseAddress) )
	{
		return XST_FAILURE;
	}

	XAxiCdma_IntrDisable(&AxiCdmaInstance, XAXICDMA_XR_IRQ_ALL_MASK);

	// Xil_DCacheFlushRange((UINTPTR)&SrcBuffer, BUFFER_BYTESIZE);
	if ( XST_SUCCESS != 
			XAxiCdma_SimpleTransfer(&AxiCdmaInstance, (UINTPTR)lookUpTrueTable, (UINTPTR)DestPLMemory, BUFFER_BYTESIZE, NULL, NULL) )
	{
		return XST_FAILURE;
	}

	while (XAxiCdma_IsBusy(&AxiCdmaInstance)){	/* Wait */;	}

	Error = XAxiCdma_GetError(&AxiCdmaInstance);
	if (Error != 0x0)
	{
		int TimeOut = RESET_LOOP_COUNT;

		/* Need to reset the hardware to restore to the correct state */
		XAxiCdma_Reset(&AxiCdmaInstance);

		while (TimeOut)
		{
			if (XAxiCdma_ResetIsDone(&AxiCdmaInstance))
			{
				break;
			}
			TimeOut -= 1;
		}

		/* Reset has failed, print a message to notify the user */
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}




